package com.h3c.ptability.mapstruct;

import com.h3c.ptability.dto.electronicSign.PtEsignDocFeatureDTO;
import com.h3c.ptability.dto.electronicSign.SignPos;
import com.h3c.ptability.dto.electronicSign.company.LisSignPos;
import com.h3c.ptability.entity.PtEsignDocFeature;
import com.h3c.ptability.vo.PtEsignDocFeatureVO;
import org.mapstruct.AfterMapping;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
import org.mapstruct.MappingTarget;
import org.mapstruct.factory.Mappers;
import org.springframework.util.StringUtils;

import java.util.List;

/**
 * @author chenyifan
 * @date 2022/5/23 11:16
 */
@Mapper
public interface PtEsignDocFeatureMapstruct {

    PtEsignDocFeatureMapstruct INSTANCE = Mappers.getMapper(PtEsignDocFeatureMapstruct.class);

    /**
     * 将模板特征转成个人签章请求中的参数
     * @param docFeature
     * @return
     */
    @Mapping(source = "keyWord", target = "key")
    SignPos docFeature2SignPos(PtEsignDocFeature docFeature);

    /**
     * 将模板特征转成静默签章请求中的参数
     * @param docFeature
     * @return
     */
    LisSignPos docFeature2LisSignPos(PtEsignDocFeature docFeature);

    /**
     * 将模板特征转成请求中的参数
     * @param docFeatureList
     * @return
     */
    @Mapping(source = "key", target = "key")
    List<SignPos> docFeatureList2SignPosList(List<PtEsignDocFeature> docFeatureList);

    /**
     * 将DTO列表转换成实体类列表
     * @param docFeatureDTOList
     * @return
     */
    List<PtEsignDocFeature> dtoList2EntityList(List<PtEsignDocFeatureDTO> docFeatureDTOList);

    /**
     * 将实体类列表转换成VO列表
     * @param features
     * @return
     */
    List<PtEsignDocFeatureVO> EntityList2VOList(List<PtEsignDocFeature> features);

    /**
     * 填充属性
     * @param voList
     */
    @AfterMapping
    default void afterEntityList2VoList(@MappingTarget List<PtEsignDocFeatureVO> voList){
        voList.stream().forEach(s->{
            if(StringUtils.hasText(s.getOrgInfoName())){
                s.setUserOrOrgSign(PtEsignDocFeature.ORG_SIGN);
            }else{
                s.setUserOrOrgSign(PtEsignDocFeature.USER_SIGN);
            }
            s.setSignLocation(s.getPosX().concat(",").concat(s.getPosY()));
        });
    }
}
